package test;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ShoppingCartServlet extends HttpServlet{
	@Override
	protected void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
		request.setCharacterEncoding("gb2312");
		String name=request.getParameter("goodsname");
		String price=request.getParameter("price");
		String count=request.getParameter("count");
		if(name!=null&&price!=null&&count!=null) {
			HttpSession session=request.getSession();
			ShoppingCart sc=(ShoppingCart)session.getAttribute("ShoppingCart");
			if(sc==null) {
				sc=new ShoppingCart();
			}
			Goods goods=new Goods(name,Integer.parseInt(price));
			Integer cnt=new Integer(count);
			sc.add(goods, cnt);
			session.setAttribute("ShoppingCart", sc);
		}
		response.sendRedirect("goods.jsp");
	}
}
